//
// Created by baka on 2025/10/16.
//


#include "cmsis_os.h"
#include "touchTask.h"
#include <stdio.h>

#include "GUI.h"
#include "GUI_Type.h"
#include "lcd.h"
#include "touch.h"
#include "uart_printf.h"


osThreadId touchTaskHandle;
osMessageQId touchQueueHandle;

#define TOUCH_WORK


void Touch_Task(void const * argument);
void touchTask(void const * argument);


volatile uint16_t line_x,line_y;



void touch_task_init(void)
{
    osThreadDef(touchTask, Touch_Task, osPriorityNormal, 0, 1024);
    touchTaskHandle = osThreadCreate(osThread(touchTask), NULL);
    osMessageQDef(touchQueue, 8, int);
    touchQueueHandle = osMessageCreate(osMessageQ(touchQueue), NULL);
}


void touchTask(void const * argument)
{
#ifndef TOUCH_WORK
    LCD_Init();
    POINT_COLOR = BLUE;
    LCD_ShowString(30, 40, 500, 24, 24, "xiao liu tong xue");
    tp_dev.init();
#endif

    for (;;)
    {
        VERBOSE("[DEBUG_LEVEL_INFO] touchTask running\r\n");
        ctp_test();
        osDelay(10);
    }
}




void Touch_Task(void const * argument)
{
#ifndef TOUCH_WORK
    GUI_PID_STATE State;

    //  /* init code for FATFS */
    //  MX_FATFS_Init();

    //  /* init code for LWIP */
    //  MX_LWIP_Init();


    GUI_Init();
    GUI_SetBkColor(GUI_BLUE);
    GUI_SetFont(GUI_FONT_32_1);
    GUI_SetColor(GUI_YELLOW);
    GUI_Clear();
#endif
    VERBOSE("Touch_Task running");
    /* Infinite loop */
    for(;;)
    {
        // 执行触摸笔检测
         GUI_TOUCH_Exec();
#ifndef TOUCH_WORK
         //获取触摸笔状态值
         GUI_TOUCH_GetState(&State);
         //是否按下
         if(State.Pressed){
             //打印触摸笔坐标信息
             GUI_DispStringAt("X:",0,0);
             GUI_DispDecAt(State.x,32,0,4);
             GUI_DispStringAt("Y:",0,24);
             GUI_DispDecAt(State.y,32,32,4);
         }
#endif
        osDelay(20);
    }
    /* USER CODE END Touch_Task */
}